﻿using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Attributes;
using Elsa.Workflows.Models;

namespace Elsa.ServerAndStudio.Web.Custom
{
    [Activity("Elsa", "自定义分类", "两个数相加")]
    public class SumWorkflow : Activity
    {
        [Input(Description = "加数")]
        public Input<int> Arg1 { get; set; } = new(1);

        [Input(Description = "被加数")]
        public Input<int> Arg2 { get; set; } = new(1);

        [Output(Description = "计算结果", DisplayName = "计算结果")]
        public Output<int> Result { get; set; } = new Output<int>();

        protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
        {
            var arg1 = Arg1.Get(context);
            var arg2 = Arg2.Get(context);   
            var result = arg1 + arg2;

            Result.Set(context, result);

            await context.CompleteActivityAsync();            
        }
    }
}
